// *************************************************************************************************
//
// MK3D Engine
// --------------------------------------
// Copyright (C) 2007-2011 Zeb (mailto: zebbey@gmail.com)
//
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// *************************************************************************************************

#ifndef __H_MK_INPUT__
#define __H_MK_INPUT__

#define DIRECTINPUT_VERSION 0x0800
#include <windows.h>
#include <dinput.h>
#pragma comment(lib, "dinput8.lib")
#pragma comment(lib, "dxguid.lib")

namespace MK3DE
{
	enum INPUT_DEVICE_TYPE
	{
		IDT_KEYBOARD,
		IDT_MOUSE,
	};

	enum COOPERATIVE_LEVEL
	{
		CL_EXC_FORE,
		CL_EXC_BACK,
		CL_NON_EXC_FORE,
		CL_NON_EXC_BACK,
	};

	enum INPUT_EVENT_TYPE
	{
		IET_KEY,
		IET_MOVE,
	};

	enum KEY_STATE
	{
		KS_PRESSED,
		KS_UNPRESSED,
	};

	typedef struct
	{
		INPUT_EVENT_TYPE type;
		union
		{
			// key event
			struct
			{
				DWORD key;
				KEY_STATE state;
			};

			// move event
			struct 
			{
				int axis;
				int offset;
			};
		};
	} InputEvent;

	typedef struct
	{
		int x;
		int y;
		int z;
	} Position;

	class CInputDevice
	{
	public:
		CInputDevice() : _enable(FALSE) {}
		virtual ~CInputDevice() {}

	public:
		virtual HRESULT UpdateImmediateData(BYTE state[], DWORD size) { return E_NOTIMPL; }

		virtual HRESULT UpdateBufferedData() { return E_NOTIMPL; }

		virtual HRESULT ClearBuffer() { return E_NOTIMPL; }

		virtual HRESULT GetKeyState(BYTE keyState[],  DWORD key, KEY_STATE& state) { return E_NOTIMPL; }

		virtual HRESULT GetInputEvent(InputEvent& event) { return E_NOTIMPL; }

		virtual HRESULT GetAbsPos(Position& pos) { return E_NOTIMPL; }

	public:
		void Enable(BOOL enable) { _enable = enable; }

		BOOL GetEnable() { return _enable; }

	protected:
		BOOL     _enable;
	};
};

#endif // __H_MK_INPUT__